package com.scar1et.simple.factory;

import com.scar1et.simple.factory.factory.OperationFactory;
import com.scar1et.simple.factory.operation.Operation;

import java.io.BufferedReader;
import java.io.InputStreamReader;

/**
 * 客户端代码
 * Created by scar1et on 15-10-24.
 */
public class Main {
    public static void main(String[] args) {
        String yesOrNo = "y";
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        while ("y".equalsIgnoreCase(yesOrNo)) {
            double numA = 0;
            double numB = 0;
            String symbol = "";
            try {
                System.out.println("请输入第一个数：numA");
                numA = Double.valueOf(br.readLine().trim());

                System.out.println("请输入运算符（+、-、×、/）：");
                symbol = br.readLine().trim();
                Operation operation = OperationFactory.createOperation(symbol);

                System.out.println("请输入第二个数：numB");
                numB = Double.valueOf(br.readLine().trim());

                operation.setNumA(numA);
                operation.setNumB(numB);

                System.out.println("您的运算结果是:" + operation.getResult());

                System.out.println("是否继续运算？（y/n）");
                yesOrNo = br.readLine().trim();

            } catch (Exception e) {
                e.printStackTrace();
                System.out.println(e.getMessage() + "");
            }
        }
    }
}
